﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc.Html;
using System.Linq.Expressions;

namespace System.Web.Mvc.Ajax
{
    public static class AjaxExtensions2
    {
        public static MvcForm BeginForm<TController>(this AjaxHelper ajaxHelper,
            Expression<Action<TController>> action, AjaxOptions ajaxOptions) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return ajaxHelper.BeginForm(actionName, controllerName, ajaxOptions);
        }

        public static MvcForm BeginForm<TController>(this AjaxHelper ajaxHelper,
            Expression<Action<TController>> action, AjaxOptions ajaxOptions, object htmlAttributes) where TController : Controller
        {
            string controllerName = MvcHelper.GetControllerName<TController>();
            MethodCallExpression call = action.Body as MethodCallExpression;
            string actionName = call.Method.Name;
            return ajaxHelper.BeginForm(actionName, controllerName, null, ajaxOptions, htmlAttributes);
        }
    }
}